let http = require('http');

/**
 * req 是属于http.IncomingMessage
 *
 * res 是属于http
 * */

let url = require('url');
let querystring = require('querystring');

let server = http.createServer((req, res) => {
    let urlObj = url.parse(req.url);
    console.log(urlObj.protocol);
    let query = urlObj.query;

    let queryObj = querystring.parse(query);
    console.log(JSON.stringify(queryObj));

    console.log('-----------------------');
    console.log(req.httpVersion);
    console.log(req.method);
    console.log(JSON.stringify(req.headers));

    res.end('end ...');
});

server.listen(8888);


// http.createServer(function (req, res) {
//     res.writeHead(200, {
//         'Content-Type': 'text/plain; charset=utf-8',
//         'X-Content-Type-Options': 'nosniff'
//     });
//     res.write('hello');
//
//     setTimeout(function(){
//         res.write('world');
//         res.end()
//     }, 2000);
//
// }).listen(3000);